package com.wangshang.serve.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wangshang.serve.po.Services;

/**
 * A data access object (DAO) providing persistence and search support for
 * Services entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.wangshang.serve.po.Services
 * @author MyEclipse Persistence Tools
 */

public class ServicesDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(ServicesDAO.class);
	// property constants
	public static final String USER_IDENTIFY = "userIdentify";
	public static final String SERVICE_NAME = "serviceName";
	public static final String ORGANIZER = "organizer";
	public static final String SAY_SOMETHING = "saySomething";
	public static final String TEL_NUM = "telNum";
	public static final String ADDRESS = "address";
	public static final String DESPAIR = "despair";
	public static final String GOOD = "good";
	public static final String PLACE_ID = "placeId";
	public static final String PLACE_MASK = "placeMask";

	protected void initDao() {
		// do nothing
	}

	public void save(Services transientInstance) {
		log.debug("saving Services instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Services persistentInstance) {
		log.debug("deleting Services instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Services findById(java.lang.Integer id) {
		log.debug("getting Services instance with id: " + id);
		try {
			Services instance = (Services) getHibernateTemplate().get(
					"com.wangshang.serve.Services", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Services instance) {
		log.debug("finding Services instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Services instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Services as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUserIdentify(Object userIdentify) {
		return findByProperty(USER_IDENTIFY, userIdentify);
	}

	public List findByServiceName(Object serviceName) {
		return findByProperty(SERVICE_NAME, serviceName);
	}

	public List findByOrganizer(Object organizer) {
		return findByProperty(ORGANIZER, organizer);
	}

	public List findBySaySomething(Object saySomething) {
		return findByProperty(SAY_SOMETHING, saySomething);
	}

	public List findByTelNum(Object telNum) {
		return findByProperty(TEL_NUM, telNum);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByDespair(Object despair) {
		return findByProperty(DESPAIR, despair);
	}

	public List findByGood(Object good) {
		return findByProperty(GOOD, good);
	}

	public List findByPlaceId(Object placeId) {
		return findByProperty(PLACE_ID, placeId);
	}

	public List findByPlaceMask(Object placeMask) {
		return findByProperty(PLACE_MASK, placeMask);
	}

	public List findAll() {
		log.debug("finding all Services instances");
		try {
			String queryString = "from Services";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Services merge(Services detachedInstance) {
		log.debug("merging Services instance");
		try {
			Services result = (Services) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Services instance) {
		log.debug("attaching dirty Services instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Services instance) {
		log.debug("attaching clean Services instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ServicesDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ServicesDAO) ctx.getBean("ServicesDAO");
	}
}